import {
	objDeepCopy
} from "@/assets/js/common.js";
let Controller = {
	methods: {
		init() {
			this.getGoodsStyleList(this);
			this.getStyleName(this);
			this.getcateg(this)
		},
		//组装分页
		paginationFunction(that, obj) {
			that.Model.paginationObject.currentPage = obj.pageIndex; // 第几页
			that.Model.paginationObject.pageSize = obj.pageSize; //  每页数量
			that.Model.paginationObject.pageTotal = obj.pageTotal; // 页总数
			that.Model.paginationObject.total = obj.total; //总数
			that.Model.paginationObject.num1 = (obj.pageIndex - 1) * obj.pageSize + 1 //num1
			//num2
			if (obj.pageTotal == obj.pageIndex) {
				that.Model.paginationObject.num2 = obj.total;
			} else {
				that.Model.paginationObject.num2 = obj.pageIndex * obj.pageSize;
			}
		},
		//获取列表
		getGoodsStyleList(that, prams) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsStyle/list',
				url: apiTest + '/sale/saleGoodsStyle/list',
				data: prams
			}).then((res) => {
				console.log(res);
				that.Model.tableData = [];
				var data = res.data;
				if (data.status == 200) {
					that.paginationFunction(that, res.data.result);
					var result = data.result.result;
					for (var i = 0; i < result.length; i++) {
						result[i].whetherLetteringIsPossible == 1 ? result[i].whetherLetteringIsPossible = '是' : result[i].whetherLetteringIsPossible =
							'否';
						result[i].officialWebsite == 1 ? result[i].officialWebsite = '上架' : result[i].officialWebsite = '下架'
						result[i].storeLoadingAndUnloading == 1 ? result[i].storeLoadingAndUnloading = '上架' : result[i].storeLoadingAndUnloading =
							'下架'
						result[i].isThereAnySpecialStyle == 1 ? result[i].isThereAnySpecialStyle = '是' : result[i].isThereAnySpecialStyle =
							'否'
						result[i].canItBeCustomized == 1 ? result[i].canItBeCustomized = '是' : result[i].canItBeCustomized = '否'
						var obj = objDeepCopy(result[i])
						that.Model.tableData.push(obj);
					}

				} else {

				}

			});
		},
		//获取 款式名称 下拉框
		getStyleName(that, prams) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsStyle/findlist',
				url: apiTest + '/sale/saleGoodsStyle/findlist',
				data: prams
			}).then((res) => {
				console.log(res);

				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].modelName,
							value: result[i].modelNo,
						}
						arr.push(obj);
					}
					that.Model.filterOption.items[2].data = objDeepCopy(arr);
					that.Model.styleName = objDeepCopy(arr);
				} else {

				}

			});
		},
		//获取 品类 下拉框
		getcateg(that, prams) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				url: '/api/saleGoodsAttribute/getGoodsAttributelist',
				// url:apiTest+'/sale/saleGoodsAttribute/getGoodsAttributelist',
				data: {
					"attributeCode": 'M03'
				}
			}).then((res) => {
				console.log(res);

				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].attributeValueName,
							value: result[i].attributeValueCode,
						}
						arr.push(obj);
					}
					that.Model.filterOption.items[1].data = objDeepCopy(arr);
					that.Model.categ = objDeepCopy(arr);
				} else {

				}

			});
		},
		//输入 品类 修改 款式名称
		changeStyleName(that, prams, option) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsStyle/findlist',
				url: apiTest + '/sale/saleGoodsStyle/findlist',
				data: prams
			}).then((res) => {
				console.log(res);

				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].modelName,
							value: result[i].modelNo,
						}
						arr.push(obj);
					}
					option[2].data = objDeepCopy(arr);
					option[2].value = arr[0].value;

					that.Model.filterOption.items = option;
				} else {

				}

			});
		},
		//输入 款式名称 修改 品类
		changeCategories(that, prams, option) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsMaster/getEntity',
				url: apiTest + '/sale/saleGoodsMaster/getEntity',
				data: prams
			}).then((res) => {
				console.log(res);

				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					option[1].value = result.category;

				} else {

				}

			});
		},
		//详情页
		showMore(row, prop = 'material') {
			// this.Model.showDetial = true;
			var styleNumber = row.modelNo;
			var row = JSON.stringify(row);
			this.$router.push({
				path: 'moreDetail',
				query: {
					activeName: prop,
					styleNumber: styleNumber,
					row: row
				},
			})
		},

		handleSizeChange(val) {
			var searchObj = this.Model.searchObj;
			var prams = {
				condition: searchObj,
				pageSize: val
			}
			this.getGoodsStyleList(this, prams);
		},
		handleCurrentChange(val) {
			var searchObj = this.Model.searchObj;
			var prams = {
				condition: searchObj,
				pageIndex: val
			}
			this.getGoodsStyleList(this, prams);
		},
		// 
		showChild(val, changeOb, option) {
			// console.log(val,changeOb,option);
			//
			if (changeOb.key == 'productCategoryCategory') {
				var prams = {
					productCategoryCategory: val.productCategoryCategory
				}
				this.changeStyleName(this, prams, option);
			} else if (changeOb.key == 'modelName') {
				var prams = {
					styleNumber: val.modelName
				}

				this.changeCategories(this, prams, option);

			}

			this.Model.searchObj = objDeepCopy(val);
		},
		toSearch(val) { //查询
			console.log(val);
			var searchObj = this.Model.searchObj;
			var prams = {
				condition: searchObj,
			}
			this.getGoodsStyleList(this, prams);
		},
		toClear(val) {
			console.log(val);
			this.Model.filterOption.items[2].data = objDeepCopy(this.Model.styleName);
			this.Model.filterOption.items[1].data = objDeepCopy(this.Model.categ);
			this.Model.searchObj = {}
			this.Model.filterOption.items[1].value = undefined;
			this.Model.filterOption.items[2].value = undefined;
		},
		toExport(val) {
			console.log(val);
		},

	}
}
export default Controller;
